﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
	public partial class modifierlotform: Form
    {
        public BindingList<Bordereau> bordereauRecherche = new BindingList<Bordereau>();
         

        private Lot lo = new Lot();
        public Lot Lo
         
        {
            get { return lo; }
            set { lo = value; }
        }

        public RecherchelotForm parent { get; set; }

		public modifierlotform()
		{ 
                InitializeComponent();
                //RAMEDEntities context = new RAMEDEntities();
                //comboBoxannexe.DataSource = context.Annexe_administratif;
                //comboBoxannexe.DisplayMember = "nom_annexe_administratif";
                
		}

        private void label2_Click(object sender, EventArgs e)
        {

        }
      

        private void btnrecherche_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {

                RAMEDEntities1 context = SingletonContext.GetContext();

                lo = context.Lots.Where(d => d.id_lot == lo.id_lot).First();
                //lo. = ((Annexe_administratif)comboBoxannexe.SelectedValue).id_annexe_administratif;
                lo.date_traitement = dateTimePickerdatetraitement.Value;
                lo.num_de_lot = utitlitaire.CasterString(txtnumerolot.Text);
                lo.total_do_lot = utitlitaire.CasterString(txttotaldelot.Text);

                foreach (Bordereau bordereau in bordereauRecherche)
                    lo.Bordereaux.Add(bordereau);
                parent.mettreAjouterFormGridViewlot();

                context.SaveChanges();
                this.Dispose();
            }   
        }
        public void InitialiserChamps()
        {

            dateTimePickerdatetraitement.Value = lo.date_traitement.Value;
            
            txtnumerolot.Text = lo.num_de_lot.ToString();
            txttotaldelot.Text = lo.total_do_lot.ToString();
            remplirDataGridView();
        }



        

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void modifierlotform_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Bordereau_Form_Modif_lot bordereau = new Bordereau_Form_Modif_lot();
            bordereau.Mlform = this;
            bordereau.Show();
        }

        public void mettreAjouterDataGridView1()
        {
            dataGridView1.DataSource = null;
            remplirDataGridView();
            dataGridView1.Update();
            dataGridView1.Refresh();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }
        private void remplirDataGridView()
        {
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.ColumnCount = 3;
            dataGridView1.Columns[0].HeaderText = "Type";
            dataGridView1.Columns[0].DataPropertyName = "type_bordereau";

            dataGridView1.Columns[1].HeaderText = "Annexe administratif";
            dataGridView1.Columns[1].DataPropertyName = "annexe_administratif";

            dataGridView1.Columns[2].HeaderText = "Nombre de Carte";
            dataGridView1.Columns[2].DataPropertyName = "Nombre_de_carte";
          
            dataGridView1.DataSource = lo.Bordereaux;
        }

        private void txtnumerolot_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs numero de lot est obligatoire", txtnumerolot, e, errorProvider1);
        }

        private void txttotaldelot_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs total de lot est obligatoire", txttotaldelot, e, errorProvider1);
        }
        
    }
}
                                                                                                                                                                                                                                                                                                                                                                        